package com.shujia.wyh.day27;

/*
    匿名内部类实现多线程
 */
public class ThreadDemo {
    public static void main(String[] args) {
        //实现多线程方式1：继承Thread类
        Thread t1 = new Thread("李毅") {
            @Override
            public void run() {
                for (int i = 1; i <= 300; i++) {
                    System.out.println(Thread.currentThread().getName() + ":" + i);
                }
            }
        };

        //实现多线程方式2：实现Runnable接口
        //借助Thread类创建线程对象
        Thread t2 = new Thread(new Runnable(){
            @Override
            public void run() {
                for(int i=1;i<=300;i++){
                    System.out.println(Thread.currentThread().getName()+":"+i);
                }
            }
        },"小虎");


        t1.start();
        t2.start();



    }
}
